const http = require('http')
const fs = require('fs');
const zlib = require('zlib')

let server = http.createServer((req,res)=>{
    
    let rs = fs.createReadStream(`www${req.url}`);
    res.on('finish',()=>{
        console.log('传输结束')
    })
    res.setHeader("Content-Encoding","gzip")
    let gz = zlib.createGzip()
    rs.pipe(gz).pipe(res)

    rs.on('error',err=>{
        res.writeHead(404)
        res.write('Not Found')
        res.end()
    })
})

server.listen(8080)